<?php


require_once("functions.php");

$_GET['date']=fixDate($_GET['date']);
$pat="INSERT INTO games (date,bowler_id,pins,handicap,total) VALUES ('%s',%d,%d,%d,%d)";
$sql=sprintf($pat,$_GET['date'],$_GET['bowler'],$_GET['pins'],$_GET['handicap'],$_GET['pins']+$_GET['handicap']);
$db=connectDB();
$rset=$db->query($sql);
$location="showBowler.php?id={$_GET['bowler']}";
update($db,$_GET['bowler']);
header("Location: {$location}");


function fixDate($d) {
	$t=explode("/",$d);
	if($t[2] < 1000) {
		$t[2]+=2000;
	}
	return sprintf("%02d/%02d/%04d",$t[0],$t[1],$t[2]);
}
?>
